<script>
import Vue from 'vue'
export default {
	onLaunch: function (options) {
		uni.getSystemInfo({
			success: function (e) {
				// #ifndef MP
				Vue.prototype.StatusBar = e.statusBarHeight;
				if (e.platform == 'android') {
					Vue.prototype.CustomBar = e.statusBarHeight + 50;
				} else {
					Vue.prototype.CustomBar = e.statusBarHeight + 45;
				};
				// #endif

				// #ifdef MP-WEIXIN
				Vue.prototype.StatusBar = e.statusBarHeight;
				let custom = wx.getMenuButtonBoundingClientRect();
				Vue.prototype.Custom = custom;
				Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
				// #endif		

				// #ifdef MP-ALIPAY
				Vue.prototype.StatusBar = e.statusBarHeight;
				Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
				// #endif
			}
		})
		uni.hideTabBar();
		const storeage = this.$utils.useStorage();
		const appid = options.query?.appid || this.$utils.$system.appid();
		if (appid) {
			// #ifdef H5
			storeage.set('APPID', appid);
			// #endif
		} else {
			uni.showModal({
				content: '授权地址不正确，请重新访问',
				showCancel: false
				, success() {
					// #ifdef H5
					globalThis.close();
					// #endif
					// #ifdef MP-WEIXIN
					uni.navigateBack();
					// #endif
				}
			})
		}
		// 初始化全局状态
		this.$store.dispatch('initGlobalstatus');
		this.$utils.$api.Ads.ads('tabbar').then((res) => {
			this.$store.dispatch('setTabbar', res);
		}).catch((err) => {
		})
		// 初始化网站配置
		this.$store.dispatch('initWebConfig');
		this.$utils.$api.Config.webconfig(this);
		// 初始化邀请码
		const icode = options.query?.icode;
		if (icode && !storeage.get('ICODE.' + appid)) {
			storeage.set('ICODE.' + appid, icode);
		}
		const puid = options.query?.puid;
		if (puid && !storeage.get('PUID.' + appid)) {
			storeage.set('PUID.' + appid, puid);
		}
		// 初始化小程序场景码
		// #ifdef MP-WEIXIN
		const scene = options.query?.scene;
		if (scene) {
			const sceneArr = decodeURIComponent(scene).split('&');
			const sceneObj = {};
			sceneArr.forEach((item) => {
				const arr = item.split('=');
				sceneObj[arr[0]] = arr[1];
			})
			if (sceneObj.puid) {
				storeage.set('PUID.' + appid, sceneObj.puid);
			}
		}
		// #endif
		// 初始化用户信息
		this.$store.dispatch('initUserInfo');
		const token = options.query?.token;
		if (token) {
			this.$store.dispatch('setUserInfo', { token })
			.catch(() => {
				this.$utils.$api.User.userinfo(this, true);
			});
		}else{
			if (this.$store.getters.hasLogin) {
				this.$utils.$api.User.userinfo(this, true);
			}
		}
		uni.hideTabBar();
	},
	onShow: function () {
		console.log('App Show')
	},
	onHide: function () {
		console.log('App Hide')
	}

}
</script>

<style>
@import "colorui/main.css";
@import "colorui/icon.css";
</style>
<style lang="scss">
@import "@/uni_modules/uview-ui/index.scss";
</style>
